package com.rongshe.hotel.service.impl;

import java.util.List;
import com.rongshe.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.rongshe.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.rongshe.hotel.domain.RsGoodUnit;
import com.rongshe.hotel.mapper.RsGoodMapper;
import com.rongshe.hotel.domain.RsGood;
import com.rongshe.hotel.service.IRsGoodService;

/**
 * 商品Service业务层处理
 * 
 * @author rongshe
 * @date 2025-02-18
 */
@Service
public class RsGoodServiceImpl implements IRsGoodService 
{
    @Autowired
    private RsGoodMapper rsGoodMapper;

    /**
     * 查询商品
     * 
     * @param id 商品主键
     * @return 商品
     */
    @Override
    public RsGood selectRsGoodById(Long id)
    {
        return rsGoodMapper.selectRsGoodById(id);
    }

    /**
     * 查询商品列表
     * 
     * @param rsGood 商品
     * @return 商品
     */
    @Override
    public List<RsGood> selectRsGoodList(RsGood rsGood)
    {
        return rsGoodMapper.selectRsGoodList(rsGood);
    }

    /**
     * 新增商品
     * 
     * @param rsGood 商品
     * @return 结果
     */
    @Transactional
    @Override
    public int insertRsGood(RsGood rsGood)
    {
        rsGood.setCreateTime(DateUtils.getNowDate());
        int rows = rsGoodMapper.insertRsGood(rsGood);
        return rows;
    }

    /**
     * 修改商品
     * 
     * @param rsGood 商品
     * @return 结果
     */
    @Transactional
    @Override
    public int updateRsGood(RsGood rsGood)
    {
        rsGood.setUpdateTime(DateUtils.getNowDate());
        return rsGoodMapper.updateRsGood(rsGood);
    }

    /**
     * 批量删除商品
     * 
     * @param ids 需要删除的商品主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRsGoodByIds(Long[] ids)
    {
        rsGoodMapper.deleteRsGoodUnitByGoodIds(ids);
        return rsGoodMapper.deleteRsGoodByIds(ids);
    }

    /**
     * 删除商品信息
     * 
     * @param id 商品主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteRsGoodById(Long id)
    {
        rsGoodMapper.deleteRsGoodUnitByGoodId(id);
        return rsGoodMapper.deleteRsGoodById(id);
    }
}
